#include <cstdio>
#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
#define int long int 
#define fread(x) ios::sync_with_stdio(x)
const int nn= 1005;

int arr[nn][nn],vis[nn][nn];
int dx[] = {-1,1,0,0};
int dy[] = {0,0,1,-1};
int m, n,cnt;
struct p{
	int x,y;
};
bool check(int x1,int y1,int x2,int y2){
	bool f = false;
	int n1 = arr[x1][y1];
	int n2 = arr[x2][y2];
	if(__gcd(n1,n2) > 1){
		f =  true;
	}
	return f;	
}
void bfs(p start){
	queue<p> q;
	q.push(start);
	
	while(q.size()){
		p tp = q.front();
		q.pop();
		for(int i=0;i<=3;i++){
			int tx = tp.x + dx[i];
			int ty = tp.y + dy[i];
			if( tx < 0 || ty < 0  || tx >= m || ty >= n || vis[tx][ty] == 1 || check(tp.x,tp.y,tx,ty) == false){
				continue;
			}
			vis[tx][ty] = 1;
			cnt ++;
			q.push((p){tx,ty});
		}
	
	}
	cout << cnt;
}
signed main() {
	fread(0);
	memset(arr,0,sizeof arr);
	memset(vis,false,sizeof vis);
//	cout << __gcd(5,5);

	cin >> m >> n;
	
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < n; j++) {
			cin >> arr[i][j];
		}
	}
	int x ,y;
	cin >> x >> y;
	bfs((p){x-1,y-1});
	return 0;
}
